﻿namespace Triad.Controls
{
    using System;
    using System.IO;
    using System.Collections;
    using System.Web.UI.Design;
    using System.ComponentModel;
    using System.Configuration;



    public class lvThemeConverter : TypeConverter
    {

        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            tfListView tflv = (tfListView) context.Instance;
            IWebApplication webApp = (IWebApplication)tflv.Site.GetService(typeof(IWebApplication));

            var result = webApp.GetProjectItemFromUrl("/MainMenu.aspx");

            string strTemp = result.PhysicalPath;
            string strPath = strTemp.Substring(0, strTemp.LastIndexOf('\\') );
            
            ArrayList cType = new ArrayList();

            string sThemeDir = strPath + "/_fw/theme/red";
            if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["Theme"]))
            {
                sThemeDir = ConfigurationManager.AppSettings["Theme"];
                sThemeDir = strPath + sThemeDir.Substring(0, strTemp.LastIndexOf('/'));
            }
            sThemeDir = sThemeDir.Replace("/", "\\");
            strTemp = sThemeDir.Substring(0,sThemeDir.LastIndexOf("\\"));
            
            string[] directories = Directory.GetDirectories(strTemp); 
            foreach (string directory in directories)
            { cType.Add(directory.Remove(0,directory.LastIndexOf("\\")+1)); }

            
           StandardValuesCollection svc = new StandardValuesCollection(cType);

            return svc;
        }

        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return true;
        }

        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            return true;
        }
    }

}
